<?php
  class feedback extends admin{
    function make_extra($buff,&$buff){
      if(!isset($_GET['start'])){
	$start = 0;
      } else {
	$start = (int)$_GET['start'];
      }

      if(!isset($_GET['end'])){
	$end = 15;
      } else {
	$end = (int)$_GET['end'];
      }

      if(isset($_GET['filter'])){
	switch($_GET['filter']){
	  case 'approved':
	    $extends = 'AND costatus = 1';
	  break;
	  case 'spam':
	    $extends = 'AND costatus = 2';
	  break;
	  case 'waiting':
	    $extends = 'AND costatus = 0';
	  break;
	  default:
	    $extends = '';
	  break;
	}
      }
      $query = $this->query("SELECT * FROM ".KLEO_TABLE_PREFIX."comments, ".KLEO_TABLE_PREFIX."users WHERE coaid = uid $extends OR coaid = 0 $extends GROUP BY coid DESC LIMIT $start,$end");

      $i=0;
      while($row = $this->fetch_array($query)){
	$GLOBALS['latest_comments'][$i] = $row;
	if(strlen($row['cotext']) > 64){
	  $GLOBALS['latest_comments'][$i]['cotext'] = substr($row['cotext'],0,48).'...';
	}
	if($row['coaid'] == 0){
	  $GLOBALS['latest_comments'][$i]['username'] = $row['cotitle'];
	}
	$GLOBALS['latest_comments'][$i]['cotext'] = '<input onclick="AddCheckbox(\'entry_'.$row['coid'].'\');" type="checkbox" name="entry_'.$row['coid'].'" id="entry_'.$row['coid'].'" /> '.$GLOBALS['latest_comments'][$i]['cotext'];

	// Waiting moderation
	if($row['costatus'] == 0){
	  $actions = '<a href="?module=admin&file=feedback.tpl&comment_action=approve&id='.$row['coid'].'">'.L_APPROVE.'</a> | <a href="?module=admin&file=feedback.tpl&comment_action=spam&id='.$row['coid'].'">'.L_SPAM.'</a>';
	// Approved
	} else if($row['costatus'] == 1){
	  $actions = '<a href="?module=admin&file=feedback.tpl&comment_action=spam&id='.$row['coid'].'">'.L_SPAM.'</a> | <a href="?module=admin&comment_action=delete&id='.$row['coid'].'" onclick="return confirm(\''.L_ASK_DELETE_COMMENT.'\');">'.L_DELETE.'</a>';
	// Spam/Not approved
	} else if($row['costatus'] == 2){
	  $actions = '<a href="?module=admin&file=feedback.tpl&comment_action=approve&id='.$row['coid'].'">'.L_NOT_SPAM.'</a> | <a href="?module=admin&file=feedback.tpl&comment_action=delete&id='.$row['coid'].'" onclick="return confirm(\''.L_ASK_DELETE_COMMENT.'\');">'.L_DELETE.'</a>';
	}
	$GLOBALS['latest_comments'][$i]['actions'] = $actions;
	$i++;
      }
      if($this->num_rows($query) == 0){
	$GLOBALS['no_comments'] = true;
      }
    }
  }
?>
